<?php

/*
|--------------------------------------------------------------------------
| Admin Web Routes 后台管理路由
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/


//标准资源路由
const RESOURCES = [
    'user' => ['name' => 'User', 'except' => []],                                 //管理员
    'role' => ['name' => 'Role', 'expect' => []],                                 //角色管理
    'permission' => ['name' => 'Permission', 'expect' => []],                     //权限管理
    'shop' => ['name' => 'Shop', 'expect' => []],                                 //商家管理
    'goods' => ['name' => 'Goods', 'expect' => []],                               //商品管理
    'order' => ['name' => 'Order', 'expect' => []],                               //订单管理
    'account' => ['name' => 'Account', 'expect' => []],                           //账号管理
];

Route::group(['namespace' => 'Admin'], function () {
    /**
     * 后台登陆及退出
     */
    Route::get('login', 'LoginController@loginForm');
    Route::post('login', 'LoginController@doLogin');
    Route::post('logout', 'LoginController@logout')->middleware('auth');
    /**
     * 需要管理员登陆的请求
     */
    Route::group(['middleware' => 'auth'], function () {
        /**
         * 不需要进行单独授权的功能
         */
        Route::get('/', 'IndexController@index');                   //系统管理首页
        Route::get('index', 'IndexController@index');                   //系统管理首页
        Route::get('initdata', 'IndexController@initdata');             //系统首页动态加载汇总项
        Route::get('indextongji', 'IndexController@index_tongji');      //系统首页会员及订单统计报表
        Route::get('dashboard', 'IndexController@dashboard');           //系统欢迎页面
        Route::post('topmenu', 'IndexController@topmenu');              //获取顶部菜单
        Route::post('leftmenu', 'IndexController@leftmenu');            //获取左侧菜单
        Route::post('unlock', 'IndexController@unlock');                //后台解锁请求
        Route::match(['get', 'post'], 'password', 'UserController@password');              //后台用户密码修改
        Route::match(['get', 'post'], 'userinfo', 'UserController@userinfo');

        Route::get('setoption', 'IndexController@setoption');                               //设置选项
        Route::get('choice/{name}', 'IndexController@choice');
        Route::match(['get', 'post'], 'account/check', 'AccountController@check')->name('account.check');  //账号验证
        Route::get('account/rate', 'AccountController@rate')->name('account.rate');     //账号验证
        Route::get('goods/list', 'GoodsController@goods_list');                         //根据商家ID获取商品列表
        Route::post('order/check', 'OrderController@check');                             //订单校验账号
        //选项项目
        /**
         * 需要验证管理员权限的功能
         **/
        Route::group(['middleware' => 'admin.permission'], function () {

            Route::post('user/status', 'UserController@switch_status')->name('user.status');             //管理员状态调整
            Route::match(['get', 'post'], 'user/password', 'UserController@password')->name('user.password');                    //管理员密码调整
            Route::get('role/{id}/permission', 'RoleController@permission')->name('role.permission');       //Role角色授权
            Route::post('role/{id}/permission', 'RoleController@permission')->name('role.setPermission');   //Role角色授权

            Route::get('config/index', 'ConfigController@index')->name('config.index');                     //系统设置
            Route::post('config', 'ConfigController@update')->name('config.update');                        //系统设置更新

            Route::match(['get', 'post'], 'user/role/{id}', 'UserController@authorization')->name('user.role'); //管理员授权
            /**
             *
             */
            Route::post('shop/status', 'ShopController@switch_status')->name('shop.status');                            //商家状态调整
            Route::post('goods/status', 'GoodsController@switch_status')->name('goods.status');                         //商品上下架处理
            Route::match(['get', 'post'], 'order/import', 'OrderController@import')->name('order.import');              //订单导入
            Route::get('account/blacklist', 'AccountController@blacklist')->name('account.blacklist');                  //黑名单列表
            //资源路由配置
            foreach (RESOURCES as $key => $v) {
                if (empty($v['except'])) {
                    Route::resource($key, $v['name'] . "Controller");
                } else {
                    Route::resource($key, $v['name'] . "Controller", ['except' => $v['except']]);
                }
            }
        });
    });
});
/**
 * 组件相关
 */
Route::group(['namespace' => 'Component'], function () {
    Route::group(['middleware' => 'auth'], function () {
        Route::get('upload', 'UploadController@upload');                     //上传图片处理
        Route::post('uploader/{client}', 'UploadController@uploader');       //
        Route::get('filelist/{client}', 'UploadController@fileLists');       //图片列表
    });
});
